package edu.columbia.gate.plugins;

import gate.Annotation;
import gate.AnnotationSet;
import gate.Document;
import gate.FeatureMap;
import gate.SimpleAnnotation;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

import java.util.*;

import gate.*;
import gate.corpora.DocumentContentImpl;
import gate.creole.*;
import gate.creole.gazetteer.AbstractGazetteer;
import gate.util.GateRuntimeException;
import gate.util.InvalidOffsetException;

public class LineBreakNormalizer extends AbstractLanguageAnalyser implements
		ProcessingResource
{

	public static final String TRANSD_DOCUMENT_PARAMETER_NAME = "document";

	/** Initialise this resource, and return it. */
	public Resource init() throws ResourceInstantiationException
	{
		return super.init();
	} // init()

	public void reInit() throws ResourceInstantiationException
	{
		init();
	} // reInit()

	/** Run the resource. */
	public void execute() throws ExecutionException
	{

		if (document == null)
			throw new GateRuntimeException("No document to process!");

		DocumentUtils.deleteAllAnnotations(document);

		String newContent = this.document.getContent().toString();
		
		newContent = newContent.replaceAll("[-\\s]{0,3}[\\r\\n]{1,3}[-\\s]{0,3}", "\n");
		
		DocumentUtils.replaceDocumentContent(document, newContent);
				
	} // execute()

} // class AnnotationSetTransfer
